package at.ttasat;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

public class CreateFolderTable {
	public static void main(String[] args) throws IOException {
		if (args.length == 0) {
			System.out.println("CreateFolderTable <folder> <tableFile>");
			return;
		}
		if (args.length != 2) {
			throw new IllegalArgumentException();
		}
		File directory = new File(args[0]);
		if (!directory.isDirectory()) {
			System.out.println("'" + args[0] + "' is not a folder");
			return;
		}
		BufferedWriter table = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(args[1]), "UTF8"));
		table.write("File name; Computer name;Tasat type;Parameters;Time (ms)\n");
		File[] files = directory.listFiles();
		for (File file : files) {
			if (file.isFile() && file.getName().endsWith(".perf")) {
				try {
					SolverTestResult result = Util.readTestResult(file);
					table.write(file.getName());
					table.write(";");
					table.write(result.getComputerName());
					table.write(";");
					table.write(Util.getTasatTypeString(result.getTasatType()));
					table.write(";");
					table.write(result.getParameters());
					table.write(";");
					table.write(Long.toString(result.getWholeTestTime()));
					table.write("\n");

				} catch (Throwable e) {
					e.printStackTrace();
				}
			}
		}
		table.close();
	}
}
